from concepts import Context
import time

import numpy as np
# 定义对象和属性
objects = ['o1', 'o2', 'o3', 'o4']
properties = ['p1', 'p2', 'p3', 'p4', 'p5']

# 定义对象与属性之间的关系矩阵（布尔值）
data = np.array([
    [1,0,0,0,0],
    [1,1,0,0,0],
    [0,0,1,0,1],
    [1,1,1,1,0]
])

# 创建一个 Context 对象
context = Context(objects, properties, data)
t1 = time.time()
# 构建概念格
lattice = context.lattice
t2 = time.time()
# 打印所有概念
i = 1
for concept in lattice:
    print(i)
    i+=1
    # print(f"概念: {concept}")
    print(f"外延: {concept.extent}")
    print(f"内涵: {concept.intent}\n")

# 可选：绘制概念格的Hasse图
# context.plot()

# 打印所有概念及其偏序关系
for i, concept1 in enumerate(lattice):
    for concept2 in lattice:
        if concept1 != concept2 and (set(concept1.extent)).issubset(set(concept2.extent))  and (set(concept2.intent)).issubset(set(concept1.intent)):
            print(f"({concept1.extent},{concept1.intent}) ≤ ({concept2.extent},{concept2.intent})")
            
print(f"时间：{t2-t1}")